﻿using System;

namespace SharpStockLib.Data
{
    /// <summary>
    /// Simple implementer of IData. Contains info about data, not about instrument.
    /// Also implements IEquatable to help comparing 2 data with each other.
    /// NOTE : this class is meant to be immutable to avoid side effects in parallel context.
    /// </summary>
    public class SimpleData : IData, IEquatable<SimpleData>
    {
        private readonly double _open;
        private readonly double _high;
        private readonly double _low;
        private readonly double _close;
        private readonly int _volume;
        private readonly DateTime _date;

        public SimpleData(double open, double high, double low, double close, int volume, DateTime date)
        {
            _open = open;
            _high = high;
            _low = low;
            _close = close;
            _volume = volume;
            _date = date;
        }

        public override string ToString()
        {
            return Date + ";" + Open + ";" + High + ";" + Low + ";" + Close + ";" + Volume;
        }

        #region IEquatable member
        public bool Equals(SimpleData other)
        {
            if (other == null)
                return false;

            // Reference equality
            if (other == this)
                return true;

            // Comparing 2 floats will raise a warning here with ReSharper. Not a big deal so far, might fix if we get issues later on.
            if (other.Open != Open)
                return false;

            if (other.High != High)
                return false;

            if (other.Low != Low)
                return false;

            if (other.Close != Close)
                return false;

            if (other.Volume != Volume)
                return false;

            if (other.Date != Date)
                return false;

            return true;
        }
        #endregion

        #region IData Members

        public double Open
        {
            get { return _open; }
        }

        public double High
        {
            get { return _high; }
        }

        public double Low
        {
            get { return _low; }
        }

        public double Close
        {
            get { return _close; }
        }

        public int Volume
        {
            get { return _volume; }
        }

        public DateTime Date
        {
            get { return _date; }
        }

        #endregion
    }
}
